// pages/me/me.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    avatarUrl: './user-unlogin.png',
    info:{
      youji:0,
      guanzhu:0,
      follow:0,
      heartAmount:0
    },
    requestResult: '',
    discovery: [],
    //
    px2rpx: 2,
    navOpacity: 0,
    statusNavBarHeight: 0,
    displayHeight: 0,
  },

  onPageScroll: function (e) {
    console.log(e)
    if (e.scrollTop <= 200) {
      this.setData({
        navOpacity: 0
      })
    }
    else if (e.scrollTop <= 250) {
      this.setData({
        navOpacity: (e.scrollTop - 200) / 50
      })
    } else {
      this.setData({
        navOpacity: 1
      })
    }
  },

  getTabBarHeight: function () {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          px2rpx: 750 / res.windowWidth
        })
      }
    })
    // 获取状态栏高度
    let { model, statusBarHeight } = wx.getSystemInfoSync();
    // 得到右上角菜单的位置尺寸
    let { height, top } = wx.getMenuButtonBoundingClientRect();
    
    let isIOSRatio = model.match(/iPhone/) ? 3 : 2;
    // 计算状态栏与导航栏的总高度
    
    let navigationBarHeight = statusBarHeight + (top - statusBarHeight) * isIOSRatio +height;
    let displayHeight = (top - statusBarHeight) * isIOSRatio +height;
    this.setData({
      statusNavBarHeight: navigationBarHeight * this.data.px2rpx,
      displayHeight: displayHeight*this.data.px2rpx
    })
  },
 

  showdiscoverydetail: function (e) {
    console.log(e)
    var art = e.currentTarget.dataset.art
    wx.navigateTo({
      url: '../discoverydetail/discoverydetail?' + 'art=' + art,
    })
  },

  showFollow: function(){
    wx.navigateTo({
      url: '../follow/follow',
    })
  },

  showHeart:function() {
    wx.navigateTo({
      url: '../myheart/myheart',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    this.setData({
      userInfo: getApp().globalData.userInfo,
    })
    this.getTabBarHeight()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.cloud.callFunction({
      // 要调用的云函数名称
      name: 'querymine'
    }).then(res => {
      console.log(res.result.data)
      that.setData({
        discovery: res.result.data
      })
    }).catch(err => {
      // handle error
    })
    //
    wx.cloud.callFunction({
      name: 'getUserInfoFromDB'
    }).then(res => {
      console.log(res)
      this.setData({
        info: res.result
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})